@extends('public.layouts')
@section('style')
    <meta name="_token" content="{{ csrf_token() }}"/>
    <style>
        .patent-th {
            text-align: center;
        }

        .patent-td {
            text-align: center;
        }
        .download-file-list{
            text-align: center;
            padding-top: 10px;
        }
    </style>
    <style>
        .task-table-th {
            text-align: center;
        }

        .task-table-td {
            text-align: center;
        }

        .keyword {
            max-width: 300px;
        }

        .keyword-btn {
            max-width: 80px;
        }

        .patent-list-th {
            text-align: center;
        }

        .patent-list-td {
            text-align: center;
        }

        .trademark-list-th {
            text-align: center;
        }

        .trademark-list-td {
            text-align: center;
        }

        #patent-list {
            max-height: 400px;
            overflow-y: auto;
        }

        #trademark-list {
            max-height: 400px;
            overflow-y: auto;
        }


    </style>
    <link rel="stylesheet" href="{{asset('admin_assets/css/bootstrap-datetimepicker.min.css')}}">
    <link rel="stylesheet" href="{{url('admin_assets/css/fileinput.min.css')}}">
    <link rel="stylesheet" href="{{url('admin_assets/css/ip.css')}}">
    <link rel="stylesheet" href="{{url('css/search.css')}}">
    <link rel="stylesheet" href="{{url('css/task.css')}}">
@stop
@section('content')
    <div class="content-wrapper" style="background-color: white">
        <section class="content">
            <div class="row">
                <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
                    <div class="box box-info"
                         style="padding-top: 0px;margin-top: 0px;border-top: 0px;border-bottom: solid 1px #0080ff;">
                        <div class="box-body" style="">
                            <div class="row">
                                <div class="col-lg-2 col-md-2 col-sm-12 col-xs-12" style="margin-top: 1%">
                                    <a href="#" title="返回首页" style="float: left"><i class="fa fa-home fa-2x"
                                                                                    style="width: 100%;color: #009aff">
                                        </i></a>
                                    <a href="#"><span
                                                style="font-size: 20px;float: left;color: #009aff">&nbsp;我的专利</span></a>
                                    <div class="clear"></div>
                                </div>
                                <div class="col-lg-5 col-md-8 col-sm-12 col-xs-12 col-lg-offset-5 col-md-offset-2 btn-div">
                                    <button type="button" class="btn btn-info div-btn" data-toggle="modal"
                                            data-target="#modal-addPatent"
                                            style="background: #009aff;float: right;margin-left: 1%;margin-top: 1%">新增专利
                                    </button>
                                    <button type="button" class="btn btn-info div-btn" data-toggle="modal"
                                            data-target="#modal-batchImport"
                                            style="background: #009aff;float: right;margin-left: 1%;margin-top: 1%">批量导入
                                    </button>
                                    {{--<form action="{{url('user/mine/myPatentSearch')}}" method="post" enctype="multipart/form-data" class="search">--}}
                                        {{--{{csrf_field()}}--}}
                                        {{--<input type="search" id="search-input" name="search">--}}
                                        {{--<button class="fa fa-search fa-lg"></button>--}}
                                    {{--</form>--}}
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            @include('public/alert')
            <div class="row">
                <div class="col-lg-3 col-md-6 col-sm-12 col-xs-12">
                    <div class="small-box bg-aqua" style="background: #37A8F4">
                        <div class="inner" style="background: #37A8F4">
                            <h3>{{$count[0]}}</h3>
                            <p>发明</p>
                        </div>
                        <div class="icon">
                            <img src="{{asset('admin_assets/img/patent_icon.png')}}"
                                 style="width: 100px;height: 100px;margin-left: 0;margin-top: -20px">
                        </div>
                        <a href="{{url('user/mine/myPatent')}}" class="small-box-footer"
                           style="background: #009aff">详情<i class="fa fa-arrow-circle-right"></i></a>
                    </div>
            </div>
                <div class="col-lg-3 col-md-6 col-sm-12 col-xs-12">
                    <div class="small-box bg-aqua" style="background: #8BC44A">
                        <div class="inner" style="background: #8BC44A">
                            <h3>{{$count[1]}}</h3>
                            <p>实用新型</p>
                        </div>
                        <div class="icon">
                            <img src="{{asset('admin_assets/img/trademark_icon.png')}}"
                                 style="width: 100px;height: 100px;margin-left: 0;margin-top: -20px">
                        </div>
                        <a href="{{url('user/mine/myTrademark')}}" class="small-box-footer" style="background: #72aa49">详情<i
                                    class="fa fa-arrow-circle-right"></i></a>
                    </div>
                </div>
                <div class="col-lg-3 col-md-6 col-sm-12 col-xs-12">
                    <div class="small-box bg-aqua" style="background: #FFBA00">
                        <div class="inner" style="background: #FFBA00">
                            <h3>{{$count[2]}}</h3>
                            <p>外观设计</p>
                        </div>
                        <div class="icon">
                            <img src="{{asset('admin_assets/img/copyright_icon.png')}}"
                                 style="width: 100px;height: 100px;margin-left: 0;margin-top: -20px">
                        </div>
                        <a href="{{url('user/mine/myCopyright')}}" style="background: #c69200" class="small-box-footer">详情<i
                                    class="fa fa-arrow-circle-right"></i></a>
                    </div>
                </div>
            </div>
            <div class="row" style="margin-left: 10px">
                <form class="form-inline" action="{{url('user/mine/myPatentCertain')}}" method="post"
                      enctype="multipart/form-data">
                    {{csrf_field()}}
                    <div class="form-group">
                        <label for="exampleInputName2">申请人</label>
                        <input type="text" class="form-control" name="applicant" id="exampleInputName2" placeholder="申请人">
                    </div>
                    <div class="form-group">
                        <label for="exampleInputEmail2">公司</label>
                        <input type="text" class="form-control" name="company" id="exampleInputEmail2" placeholder="公司">
                    </div>
                    <label for="exampleInputName2">类型</label>
                    <select class="form-control" name="second_type">
                        <option value=" " >不填</option>
                        <option value="1" >发明</option>
                        <option value="2" >实用新型</option>
                        <option value="3" >外观设计</option>
                    </select>
                    <div class="form-group">
                        <label for="exampleInputEmail2">专利号</label>
                        <input type="text" class="form-control" name="number" id="exampleInputEmail2" placeholder="专利号">
                    </div>
                    <div class="form-group">
                        <label for="exampleInputEmail2">名称</label>
                        <input type="text" class="form-control" name="product_name" id="exampleInputEmail2" placeholder="名称">
                    </div>
                    <div class="form-group">
                        <label for="exampleInputName2">申请日期</label>
                        <input type="date" name="created_at" class="form-control" id="exampleInputName2" >
                    </div>
                    <div class="form-group">
                        <label for="exampleInputName2">授权日期</label>
                        <input type="date" name="authority_time" class="form-control" id="exampleInputName2" >
                    </div>
                    <div class="form-group">
                        <label for="exampleInputEmail2">发明人</label>
                        <input type="text" class="form-control" name="inventor" id="exampleInputEmail2" placeholder="名称">
                    </div>
                    <button type="submit" class="btn btn-default">搜索</button>
                </form>
            </div>
            <div class="row" style="margin-top: 2%">
                <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
                    <div class="table-responsive">
                        <table class="table table-bordered">
                            <thead>
                            <tr>
                                <th class="patent-th">序号</th>
                                <th class="patent-th">申请人</th>
                                <th class="patent-th">公司</th>
                                <th class="patent-th">类型</th>
                                <th class="patent-th">专利号</th>
                                <th class="patent-th">名称</th>
                                <th class="patent-th">申请日期</th>
                                <th class="patent-th">授权日期</th>
                                <th class="patent-th">发明人</th>
                                <th class="patent-th">代理人</th>
                                <th class="patent-th">进度</th>
                                <th class="patent-th">年费缴纳情况</th>
                                <th class="patent-th">报件资料</th>
                                <th class="patent-th">官方文件</th>
                                <th class="patent-th">操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            @if($patent->isEmpty())
                                <tr>
                                    <td class="patent-td" colspan="15"><h3 align="center">暂无数据</h3></td>
                                </tr>
                            @else
                                @foreach($patent as $k =>$v)
                                    <tr>
                                        <td class="patent-td" style="vertical-align: middle">{{$k+1}}</td>
                                        <td class="patent-td" style="vertical-align: middle">{{$v['applicant']}}</td>
                                        <td class="patent-td" style="vertical-align: middle">{{$v['company']}}</td>
                                        <td class="patent-td"
                                            style="vertical-align: middle">{{$v['SecondType']['name']}}</td>
                                        <td class="patent-td" style="vertical-align: middle">{{$v['number']}}</td>
                                        <td class="patent-td" style="vertical-align: middle">{{$v['name']}}</td>
                                        <td class="patent-td" style="vertical-align: middle">{{date("Y-m-d",strtotime($v['created_at']))}}</td>
                                        <td class="patent-td"
                                            style="vertical-align: middle">
                                            @if(!empty($v['authority_time']))
                                                {{date("Y-m-d",strtotime($v['authority_time']))}}
                                            @endif
                                        </td>
                                        <td class="patent-td" style="vertical-align: middle">{{$v['inventor']}}</td>
                                        <td class="patent-td" style="vertical-align: middle">
                                            @if($v['Progress']->isEmpty())
                                                暂无
                                            @elseif(empty($v['Progress']->last()['agent']))
                                                暂无
                                            @else
                                                {{$v['Progress']->last()['agent']}}
                                            @endif
                                        </td>
                                        <td class="task-table-td task_flow patent-td"
                                            style="vertical-align: middle;cursor: pointer"
                                            data-toggle="modal"
                                            data-target="#task_flowModal"
                                            data-pid="{{$v['product_id']}}"
                                            data-progressid="{{$v['id']}}"
                                            data-second_type_id="{{$v['second_type_id']}}">
                                            @if($v['Progress']->isEmpty())
                                                已完成
                                            @else
                                                @if($v['Progress']->last()['is_renew'])
                                                    @if($progress[$v['Progress']->last()['progress_list_id']]['flag'])
                                                        已完成
                                                    @else
                                                        未完成
                                                    @endif
                                                @else
                                                    {{$progress[$v['Progress']->last()['progress_list_id']]['name']}}
                                                @endif
                                            @endif
                                        </td>
                                        {{--<td class="patent-td" style="vertical-align: middle">--}}
                                            {{--@if($v['Progress']->isEmpty())--}}
                                                {{--已完成--}}
                                            {{--@else--}}
                                                {{--@if($v['Progress']->last()['is_renew'])--}}
                                                    {{--@if($progress[$v['Progress']->last()['progress_list_id']]['flag'])--}}
                                                        {{--已完成--}}
                                                    {{--@else--}}
                                                        {{--未完成--}}
                                                    {{--@endif--}}
                                                {{--@else--}}
                                                    {{--{{$progress[$v['Progress']->last()['progress_list_id']]['name']}}--}}
                                                {{--@endif--}}
                                            {{--@endif--}}
                                        {{--</td>--}}
                                        <td class="patent-td"
                                            style="vertical-align: middle">
                                            @if(!empty($v['authority_time']))
                                                {{date("Y-m-d",strtotime("+".$v['FirstType']['time']." year",strtotime($v['authority_time'])))}}
                                            @endif
                                        </td>

                                        <td class="patent-td" style="vertical-align: middle">
                                            @if(empty($v['file']))
                                                未上传
                                            @else
                                                <a href="{{asset('Uploads/resources/'.$v['file'])}}">
                                                    查看资料
                                                </a>
                                            @endif
                                                <a href="#" data-toggle="modal" product="{{$v['id']}}"     onclick="setReport($(this))"
                                                   data-target="#uploadReport">
                                                    @if(empty($v['file']))
                                                        上传
                                                    @else
                                                        重新上传
                                                    @endif
                                                </a>
                                        </td>
                                        <td class="patent-td" style="vertical-align: middle">
                                                @if($v['is_download_notice']==0)
                                                    <a href="#"  data-toggle="modal" product="{{$v['id']}}" onclick="se($(this))" data-target="#modal-official-document">上传资料</a>
                                                @else
                                                <a href="#" product="{{$v['id']}}" onclick="se($(this))"  data-toggle="modal" data-target="#modal-official-document">上传资料</a>
                                                {{--<a href="javascript:void(0);" product="{{$v['id']}}" onclick="ajxZip($(this))">下载资料</a>--}}
                                                <a href="#"  product="{{$v['id']}}" onclick="s($(this));" data-toggle="modal" data-target="#modal-download-file">下载资料</a>
                                                <textarea style="display: none" >{{json_encode($v['Files'])}}</textarea>
                                                @endif
                                        </td>
                                        <td class="patent-td" style="vertical-align: middle">
                                            <a href="#" data-toggle="modal" product="{{$v['id']}}"
                                               typea="{{$v['SecondType']['id']}}" inventor="{{$v['inventor']}}"
                                               applicant="{{$v['applicant']}}" name="{{$v['name']}}"
                                               number="{{$v['number']}}" onclick="setV($(this))"
                                               data-target="#modal-pay-annual-fee">代缴年费&nbsp;</a>
                                            @if($v['Progress']->isNotEmpty())
                                                @if($v['is_download_notice']==3)
                                                    等待邮寄
                                                @elseif($v['is_download_notice']==4)
                                                    <a href="#" rel="{{$v['tracking_number']}}" onclick="ss($(this));" data-toggle="modal" data-target="#modal-tracking-number">查看单号</a>
                                                @else
                                                    @if( !empty($v['Progress']->first()))
                                                        <a href="#"  onclick="set($(this))" pid="{{ $v['Progress']->first()['id'] }}" address="{{empty($v['User'])?"":$v['User']['address']}}" rel="{{$v['id']}}" data-toggle="modal" data-target="#user-address">&nbsp;申请纸质通知书&nbsp;</a>
                                                    @endif
                                                @endif
                                            @endif
                                            @php($prg=$v['Progress'])
                                            @php($len=count($prg))
                                            @if(empty($prg[$len-1]['first_pay_time']))
                                                <a href="{{url('user/mine/delProduct',['id'=>$v['id']])}}"
                                                   onclick="return confirm('确定要删除吗?');">&nbsp;删除</a>
                                            @else
                                                {{--<a href="">删除</a>--}}
                                            @endif
                                        </td>
                                    </tr>
                                @endforeach
                            @endif
                            </tbody>
                        </table>
                        <div class="">
                            {!! $patent->links() !!}
                        </div>
                    </div>
                </div>
            </div>
        </section>
    </div>
    @include('public.addPatentModal')
    @include('public.batchImportModal')
    @include('public.payAnnualFeeModal')
    @include('public.userAddress')
    @include('public.uploadReport')
    @include('public.official-document-mineModal')
    @include('public.download-fileModal')
    @include('public.trackingNumberModal')
    @include('public/taskFlowModal')
@stop
@section('javascript')
    <script src="{{asset('admin_assets/js/fileinput.min.js')}}"></script>
    <script src="{{asset('admin_assets/js/fileinput_locale_zh.js')}}"></script>
    <script src="{{asset('admin_assets/js/bootstrap-datetimepicker.min.js')}}"></script>
    <script src="{{asset('js/ip.js')}}"></script>
    <script>
        $("#inputFile").fileinput({
            language: 'zh',
            autoReplace: false,
            maxFileCount: 1,
            allowedFileExtensions: ["zip","rar","7z"],
            browseClass: "btn btn-primary",
            textEncoding:'UTF-8',
            showUpload: false,
            showCancel: true,
            previewFileIcon: "<i class='glyphicon glyphicon-king'></i>"
        });
        $("#inputFile1").fileinput({
            language: 'zh',
            autoReplace: false,
            maxFileCount: 1,
            allowedFileExtensions: ["jpeg","jpg", "png", "pdf"],
            browseClass: "btn btn-primary",
            textEncoding:'UTF-8',
            showUpload: false,
            showCancel: true,
            previewFileIcon: "<i class='glyphicon glyphicon-king'></i>"
        });
        $(".form_datetime").datetimepicker({
            format: "yyyy-mm-dd hh:ii:ss",
            autoclose: true,
            todayBtn: true,
            minuteStep: 10,
            language: "en"
        });
        function se(e) {
            $('#office-pid').val(e.attr('product'));
        }
        function setV(e) {
            $('#product').val(e.attr('product'));
            $('#pay_patent_name').val(e.attr('name'));
            $('#pay_patent_num').val(e.attr('number'));
            $('#pay_patent_first_apply').val(e.attr('applicant'));
            $('#pay_inventor').val(e.attr('inventor'));
            $('#extension_type').val(e.attr('typea'));
        }
        function set(e) {
            $('#p').val(e.attr('rel'));
            $('#pro').val(e.attr('pid'));
            $('#address').val(e.attr('address'));
        }
        function setReport(e) {
            $('#upload-pro').val(e.attr('product'));
        }
        function ajxZip(e) {
            $.ajax({
                url: '{{url("user/mine/ajxZip")}}',
                type: 'post',
                dataType: "json",
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content')
                },
                data:{
                    'id':e.attr('rel')
                },
                success: function (data) {
                    window.location.href=data;
                }

            });
        }

        function s(e) {
            $('#download-a').attr('rel',e.attr('product'))
            var list=eval(e.next().text());
            var size=list.length;
            var tb=$('#file-downloads');
            tb.empty();
            if(size==0)
            {
                tb.append('<tr>');
                tb.append('<td class="text-muted" style="background-color: white" colspan="4"><h3 align="center">暂无数据</h3></td>');
                tb.append('</tr>');
            }
            for (var i=0;i<size;i++)
            {
                if (list[i]['yn']!=1){
                    var yn="未读";
                }
                else {
                    var yn="已读";
                }

                tb.append('<tr>');
                tb.append('<td class="text-muted download-file-list">'+(i+1) +'.</td>');
                tb.append('<td class="mailbox-name download-file-list" style="text-align: center">'+list[i]['name']+'</td>');
                tb.append('<td class="mailbox-name" style="text-align: center;padding-top: 10px;">' + yn + '</td>');
                tb.append('<td class="mailbox-date download-file-list">'+formatDate(list[i]['created_at'])+'</td>');/*"+getUrl(list[i]['url'])+"*/
                tb.append("<td onclick='test("+ list[i].id+");' class='mailbox-subject download-file-list'><a href='"+getUrl(list[i]['url'])+"'><i class='fa fa-download' style='color: #009aff;cursor: pointer'></i></a></td>");
                tb.append('</tr>');
            }
            test = function (id){
                console.log(id);
                $.ajax({
                    type: 'POST',
                    url: '{{url('user/mine/yes')}}',
                    data: { id:id, _token:"{{csrf_token()}}"},
                    dataType: 'json',
                    success: function(data){
                        console.log(data);
                    },
                    error: function(xhr, status, error){
                        console.log(xhr);
                        console.log(status);
                        console.log(error);
                    }
                });
            }

        }

        /**
         * 格式化时间
         * @param str
         * @returns {string}
         */
        function formatDate(str) {
            var date=new Date(str);
            return date.getFullYear()+'-'+date.getMonth()+'-'+date.getDay();
        }
        function getUrl(str) {
            var url=window.location.href;
            var arr=url.split("user");
            return arr[0]+"Uploads/resources/"+str;
        }
        function ss(e) {
            $('#trackingNumber').val(e.attr('rel'));
        }
    </script>
    <script>
        $(".task_flow").click(function () {
            var product_id = $(this).attr("data-pid");
            var progressid = $(this).attr("data-progressid");
            var second_type_id = $(this).attr("data-second_type_id");
            $.ajax({
                url: '{{url('user/operate/getProjectSchedule')}}',
                type: 'post',
                dataType: 'json',
                data: {
                    'pid': product_id,
                    'p_id': progressid,
                    's_id': second_type_id
                },
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content')
                },
                success: function (data) {

                    // console.log(data);

                    var e = $('#task_progress');
                    e.empty();
                    if (data.length) {
                        for (var i = 0, size = data.length; i < size; i++) {


                            var item = data[i];

                            if (item['state'] == 1) {
                                e.append('  <div class="l_content_box" >\n' +
                                        '            <div class="a_tm_info" >\n' +
                                        '                <div class="l_left">\n' +
                                        '                    <div>\n' +
                                        '                        <p class="l_green">' + item['time'].split(' ')[0] + '</p>\n' +
                                        '                        <p class="l_green">' + item['time'].split(' ')[1] + '</p>\n' +
                                        '                    </div>\n' +
                                        '                </div>\n' +
                                        '                <div class="l_center l_green" >\n' +
                                        '                    <i class="fa fa-check-circle fa-2x"></i>\n' +
                                        '                </div>\n' +
                                        '                <div class="l_right" style="">\n' +
                                        '                    <div>\n' +
                                        '                        ' +
                                        '                        <p class="l_green l_quickInformation" title="' + item['operate'] + '">' + item['operate'] + '</p>\n' +
                                        '                    </div>\n' +
                                        '                </div>\n' +
                                        '            </div>\n' +
                                        '        </div>');
                            }
//                          else if(i==1){
//                              e.append('  <div class="l_content_box">\n' +
//                                  '            <div class="a_tm_info" >\n' +
//                                  '                <div class="l_left">\n' +
//                                  '                    <div>\n' +
//                                  '                        <p class="l_orange">'+item['time'].split(' ')[0]+'</p>\n' +
//                                  '                        <p class="l_orange">'+item['time'].split(' ')[1]+'</p>\n' +
//                                  '                    </div>\n' +
//                                  '                </div>\n' +
//                                  '                <div class="l_center l_orange" >\n' +
//                                  '                    <i class="fa fa-check-circle fa-2x"></i>\n' +
//                                  '                </div>\n' +
//                                  '                <div class="l_right" style="">\n' +
//                                  '                    <div>\n' +
//                                  '                        ' +
//                                  '                        <p class="l_orange l_quickInformation" title="'+item['operate']+'">'+item['operate']+'</p>\n' +
//                                  '                    </div>\n' +
//                                  '                </div>\n' +
//                                  '            </div>\n' +
//                                  '        </div>');
//                          }
                            else {
                                e.append('  <div class="l_content_box">\n' +
                                        '            <div class="a_tm_info" >\n' +
                                        '                <div class="l_left">\n' +
                                        '                    <div>\n' +
                                        '                        <p class="l_gray">' + item['time'].split(' ')[0] + '</p>\n' +
                                        '                        <p class="l_gray">' + item['time'].split(' ')[1] + '</p>\n' +
                                        '                    </div>\n' +
                                        '                </div>\n' +
                                        '                <div class="l_center l_gray" >\n' +
                                        '                    <i class="fa fa-check-circle fa-2x"></i>\n' +
                                        '                </div>\n' +
                                        '                <div class="l_right" style="">\n' +
                                        '                    <div>\n' +
                                        '                        ' +
                                        '                        <p class="l_gray l_quickInformation" title="' + item['operate'] + '">' + item['operate'] + '</p>\n' +
                                        '                    </div>\n' +
                                        '                </div>\n' +
                                        '            </div>\n' +
                                        '        </div>');
                            }

                        }
                    } else {

                    }
                }

            });

        });
    </script>
@stop
